﻿/*
  Copyright © Alexander G. Bykin, Russia 2009-2010
  This source is subject to the Microsoft Public License (Ms-PL).
  Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  All other rights reserved.
*/

namespace System.Windows.Controls.UnitTests
{
    using System.Windows.Controls.Primitives;
    using Microsoft.Silverlight.Testing;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class DataGroupTestProperties : DataGroupTestBase
    {
        #region Helper Properties

        /// <summary>
        /// Gets the <see cref="DataFilter"/> app.
        /// </summary>
        private DataGroupApp DataGroupApp
        {
            get
            {
                return this.DataGroupAppBase as DataGroupApp;
            }
        }

        /// <summary>
        /// Gets the <see cref="DataFilter"/>.
        /// </summary>
        private DataGroup DataGroup
        {
            get
            {
                return this.DataGroupApp.dataGroup;
            }
        }

        #endregion Helper Properties

        #region Initialization

        /// <summary>
        /// Initializes the test framework.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            this.DataGroupAppBase = new DataGroupApp();
        }

        #endregion Initialization

        #region Test ButtonAddGroupTooltip

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonAddGroupTooltip_IsSet()
        {
            string actual = "test tooltip";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonAddGroupTooltip = actual;
                    Assert.AreEqual(this.DataGroup.ButtonAddGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonAddGroupTooltip_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonAddGroupTooltip = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonAddGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonDeleteGroupTooltip

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonDeleteGroupTooltip_IsSet()
        {
            string actual = "test tooltip";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonDeleteGroupTooltip = actual;
                    Assert.AreEqual(this.DataGroup.ButtonDeleteGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonDeleteGroupTooltip_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonDeleteGroupTooltip = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonDeleteGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonClearGroupTooltip

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonClearGroupTooltip_IsSet()
        {
            string actual = "test tooltip";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonClearGroupTooltip = actual;
                    Assert.AreEqual(this.DataGroup.ButtonClearGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonClearGroupTooltip_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonClearGroupTooltip = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonClearGroupTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonApplyTooltip

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonApplyTooltip_IsSet()
        {
            string actual = "test tooltip";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonApplyTooltip = actual;
                    Assert.AreEqual(this.DataGroup.ButtonApplyTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonApplyTooltip_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonApplyTooltip = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonApplyTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonApplyContent

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonApplyContent_IsSet()
        {
            string actual = "test content";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonApplyContent = actual;
                    Assert.AreEqual(this.DataGroup.ButtonApplyContent, actual);
                    ButtonBase button = this.GetTemplatePart<ButtonBase>("btnApply");
                    Assert.IsNotNull(button);
                    Assert.AreEqual(button.Content, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonApplyContent_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonApplyContent = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonApplyContent, actual);
                    ButtonBase button = this.GetTemplatePart<ButtonBase>("btnApply");
                    Assert.IsNotNull(button);
                    Assert.AreNotEqual(button.Content, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonCancelTooltip

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonCancelTooltip_IsSet()
        {
            string actual = "test tooltip";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonCancelTooltip = actual;
                    Assert.AreEqual(this.DataGroup.ButtonCancelTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonCancelTooltip_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonCancelTooltip = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonCancelTooltip, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test ButtonCancelContent

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonCancelContent_IsSet()
        {
            string actual = "test content";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonCancelContent = actual;
                    Assert.AreEqual(this.DataGroup.ButtonCancelContent, actual);
                    ButtonBase button = this.GetTemplatePart<ButtonBase>("btnCancel");
                    Assert.IsNotNull(button);
                    Assert.AreEqual(button.Content, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_ButtonCancelContent_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.ButtonCancelContent = actual;
                    Assert.AreNotEqual(this.DataGroup.ButtonCancelContent, actual);
                    ButtonBase button = this.GetTemplatePart<ButtonBase>("btnCancel");
                    Assert.IsNotNull(button);
                    Assert.AreNotEqual(button.Content, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test OnApplyButtonBeforeClick

        [TestMethod]
        [Asynchronous]
        public void Check_OnApplyButtonBeforeClick_Fired()
        {
            bool actual = true;
            bool expected = false;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                this.DataGroup.OnApplyButtonBeforeClick += (s, e) =>
                {
                    expected = true;
                };
                this.DataGroup.ApplyFilters();
                Assert.AreEqual(expected, actual);
            });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test OnCancelButtonBeforeClick

        [TestMethod]
        [Asynchronous]
        public void Check_OnCancelButtonBeforeClick_Fired()
        {
            bool actual = true;
            bool expected = false;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                this.DataGroup.OnCancelButtonBeforeClick += (s, e) =>
                {
                    expected = true;
                };
                this.DataGroup.CancelFilters();
                Assert.AreEqual(expected, actual);
            });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test OnApplyButtonAfterClick

        [TestMethod]
        [Asynchronous]
        public void Check_OnApplyButtonAfterClick_Fired()
        {
            bool actual = true;
            bool expected = false;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                this.DataGroup.OnApplyButtonAfterClick += (s, e) =>
                {
                    expected = true;
                };
                this.DataGroup.ApplyFilters();
                Assert.AreEqual(expected, actual);
            });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test OnCancelButtonAfterClick

        [TestMethod]
        [Asynchronous]
        public void Check_OnCancelButtonAfterClick_Fired()
        {
            bool actual = true;
            bool expected = false;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                this.DataGroup.OnCancelButtonAfterClick += (s, e) =>
                {
                    expected = true;
                };
                this.DataGroup.CancelFilters();
                Assert.AreEqual(expected, actual);
            });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test GroupPropertyPathHeader

        [TestMethod]
        [Asynchronous]
        public void Check_GroupPropertyPathHeader_IsSet()
        {
            string actual = "test content";

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.GroupPropertyPathHeader = actual;
                    Assert.AreEqual(this.DataGroup.GroupPropertyPathHeader, actual);
                });

            this.EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Check_GroupPropertyPathHeader_IsNotNull()
        {
            string actual = string.Empty;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.GroupPropertyPathHeader = actual;
                    Assert.AreNotEqual(this.DataGroup.GroupPropertyPathHeader, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion

        #region Test DomainDataSource

        [TestMethod]
        [Asynchronous]
        public void Check_DomainDataSource_IsSet()
        {
            DomainDataSource actual = new DomainDataSource();

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
                {
                    this.DataGroup.DomainDataSource = actual;
                    Assert.AreEqual(this.DataGroup.DomainDataSource, actual);
                });

            this.EnqueueTestComplete();
        }

        #endregion
    }
}
